function A=regenerate_im(E)

%Regenerates an image from the matrix of errors E

[M,N]=size(E);
A_exp=zeros(M+1,N+2);
for i=2:M+1
    line_ant=A_exp(i-1,:);
    for j=2:N+1
       if E(i-1,j-1)==256 %run mode
          A_exp(i,j)=A_exp(i,j-1);
       else
       a=A_exp(i,j-1);
       b=line_ant(j);
       c=line_ant(j-1);
       d=line_ant(j+1);
       A_exp(i,j)=E(i-1,j-1)+predictorMED(a,b,c,d);
       end
   end
end
A=A_exp(2:M+1,2:N+1);